package net.huashitong.giszd.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import net.huashitong.giszd.entity.NodeNewtemplet;
import net.huashitong.giszd.filter.NodeNewtempletFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class NodeNewtempletDao extends StringDao<NodeNewtemplet> {


    /**
     * 条件查询
     * @param filter
     * @return
     */
    public List<NodeNewtemplet> getNodeTempletInfo(NodeNewtempletFilter filter){
        GenericQuery query = createQuery("obj");
        if (filter.getNodeId()!=null&&!"".equals(filter.getNodeId()))
            query.append(" and obj.nodeId =:nodeId").setParam("nodeId",filter.getNodeId());
        if (filter.getNodeName()!=null&&!"".equals(filter.getNodeName()))
            query.append(" and obj.nodeName =:nodeName").setParam("nodeName",filter.getNodeName());
        if (filter.getResDept()!=null&&!"".equals(filter.getResDept()))
            query.append(" and obj.resDept =:resDept").setParam("resDept",filter.getResDept());
        if (filter.getResUser()!=null&&!"".equals(filter.getResUser()))
            query.append(" and obj.resUser =:resUser").setParam("resUser",filter.getResUser());
        if (filter.getOperatorUser()!=null&&!"".equals(filter.getOperatorUser()))
            query.append(" and obj.operatorUser =:operatorUser").setParam("operatorUser",filter.getOperatorUser());
        if (filter.getType()!=null&&!"".equals(filter.getType()))
            query.append(" and obj.type =:type").setParam("type",filter.getType());
        if (filter.getPlanTime()!=null&&!"".equals(filter.getPlanTime()))
            query.append(" and obj.planTime =:planTime").setParam("planTime",filter.getPlanTime());
        if (filter.getFactTime()!=null&&!"".equals(filter.getFactTime()))
            query.append(" and obj.factTime =:factTime").setParam("factTime",filter.getFactTime());
        if (filter.getPlanBeginDate()!=null&&!"".equals(filter.getPlanBeginDate()))
            query.append(" and obj.planBeginDate =:planBeginDate").setParam("planBeginDate",filter.getPlanBeginDate());
        if (filter.getFactFinishDate()!=null&&!"".equals(filter.getFactFinishDate()))
            query.append(" and obj.factFinishDate =:factFinishDate").setParam("factFinishDate",filter.getFactFinishDate());
        if (filter.getStatus()!=null&&!"".equals(filter.getStatus()))
            query.append(" and obj.status =:status").setParam("status",filter.getStatus());
        if (filter.getNodeType()!=null&&!"".equals(filter.getNodeType())){
            query.append(" and obj.nodeType =:nodeType").setParam("nodeType",filter.getNodeType());
        }
        if (filter.getPaging() == null){
            query.append(" ORDER BY obj.nodeId+0 ASC");
        }
        return query.listResult();
    }
}
